package com.qubuyer.business.good.viewmodel

import com.qubuyer.core.framework.BaseModel
import com.qubuyer.core.http.HttpResult
import com.qubuyer.repository.entitys.*
import com.qubuyer.repository.services.ApiService

class SOModel : BaseModel() {

    private val api: ApiService by injectApi()

    suspend fun buyNow(goodsNum: Int, goodsId: Int, itemId: Int): HttpResult<SOGoodInfoEntity?> {
        return api.buyNow(goodsNum, goodsId, itemId)
    }

    suspend fun buyFromCart(): HttpResult<SOGoodInfoEntity?> {
        return api.buyFromCart()
    }

    suspend fun buyNowPlace(goodsNum: Int, goodsId: Int, itemId: Int, addressId: String, addressMobile: String, userNote: String, invoiceEntity: MineInvoiceEntity?): HttpResult<GoodSOResultEntity?> {
        return api.buyNowPlace(
                goodsNum, goodsId, itemId, addressId,
                if (invoiceEntity?.isUse != 0) "0" else "1",
                invoiceEntity?.type?.toString() ?: "",
                invoiceEntity?.companyDutyparagraph,
                invoiceEntity?.companyName,
                invoiceEntity?.email,
                invoiceEntity?.content,
                userNote,
//                invoiceEntity?.phone
                addressMobile//Note:备注：字段名是发票的电话，但是，旧代码传的是快递地址的电话，暂时按旧代码的来
        )
    }

    suspend fun buyFromCartPlace(addressId: String, addressMobile: String, userNote: String, invoiceEntity: MineInvoiceEntity?): HttpResult<GoodSOResultEntity?> {
        return api.buyFromCartPlace(addressId,
                if (invoiceEntity?.isUse != 0) "0" else "1",
                invoiceEntity?.type?.toString() ?: "",
                invoiceEntity?.companyDutyparagraph,
                invoiceEntity?.companyName,
                invoiceEntity?.email,
                invoiceEntity?.content,
                userNote,
//                invoiceEntity?.phone
                addressMobile //Note:备注：字段名是发票的电话，但是，旧代码传的是快递地址的电话，暂时按旧代码的来
        )
    }

    suspend fun addressList(): HttpResult<List<MineAddressEntity>?> {
        return api.addressList()
    }

    suspend fun priceCalculation(goodsNum: Int?, goodsId: Int?, itemId: Int?, addressId: String): HttpResult<CalcOrderPriceResultEntity?> {
        return api.priceCalculation(goodsNum, goodsId, itemId, addressId)
    }

    suspend fun getWxPayParams(id:String): HttpResult<WechatPayParamEntity?> {
        return api.getWxPayParams(id)
    }

    suspend fun getAliPayParams(id:String): HttpResult<String?> {
        return api.getAliPayParams(id)
    }

    suspend fun getOrderStatus(id:String): HttpResult<PayResultEntity?> {
        return api.getOrderStatus(id)
    }
}